package com.CMC.yhdeng;

import java.io.IOException;
import java.util.ArrayList;

import android.util.JsonReader;
import android.util.JsonToken;

public class ChapterContent extends UnitBase{
	public ArrayList<UnitContent> objs;
	private int current=0;
	public int getCurrent() {
		return current;
	}

	public void setCurrent(int current) {
		this.current = current;
	}

	

	public ChapterContent() {
		super();
		objs = new ArrayList<UnitContent>();
	}

	public UnitContent getCurrentUnit()
	{
		return objs.get(current);
	}
	public String getCurrentTitle() {

		return objs.get(current++).title;
	}

	public Boolean quizEnd() {
		return current >= objs.size() ? true : false;
	}

	public boolean read(JsonReader reader) throws IOException{
		reader.beginObject();
		readBaseMember(reader, "chapter_id", "chapter_title");
		
		String tag=reader.nextName();
		if (tag.compareTo("chapter_content") == 0) {

			JsonToken tok = reader.peek();
			if (tok != JsonToken.NULL) {
				reader.beginArray();
				while (reader.hasNext()) {
					UnitContent obj = new UnitContent();
					obj.read(reader);
					objs.add(obj);
				}
				reader.endArray();
			}else reader.nextNull();

		}
	     reader.endObject();
		return true;
		
	}
}
